Skip to content

UTB parity 2/4: V2 trust-base entry codec, strict signatures, bounded CBOR - #2

Merged
ristik merged 1 commit into
mainfrom
dev3/java-2-entry
Nov 8, 2026
Merged

ristik merged 1 commit into
mainfrom
dev3/java-2-entry

Conversation

@ristik

@ristik ristik commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Owner §51, plan briefs/java-utb-parity-plan.md, PR 2 (stacked on #1). Mirrors JS RootTrustBaseV2.ts + MaxEntryTest, Rust trust_base_entry.rs + tests/trust_base_{entry_vectors,entry_max,signature_limits}.rs (Rust dev2/upstream-utb 7a6f11a as the reference for the §49 limits).

  • TrustBaseEntry (package org.unicitylabs.sdk.api.bft.trustbase): tag 39000, version 2, exact 10-field array, deterministic re-encode check, entryId = SHA-256(sigBytes) (signature field CBOR null), unsigned-64 epoch/round/weight as long bit patterns, structure rules, exact threshold floor(2W/3)+1, genesis/non-genesis shape, strict 65-byte low-S recoverable signatures bound to the member key (64-byte compact form refused), verifySuccessor.
  • Typed errors: TrustBaseEncodingException, TrustBaseInvalidException, TrustBaseChainException, TrustBaseSignatureException (base TrustBaseException, unchecked).
  • Bounds: 128 KiB (checked first), 256 members and 256 signatures from the array/map header before any element is read, 128-byte node ids, weight 1..2^40. The parser slack (272) is not an allowance: 257 is refused.
  • CborDeserializer: decodeArrayAtMost/decodeMapAtMost (header-count bound), decodeTextString is now strict UTF-8 (was platform default charset with replacement).
  • Vectors vendored byte for byte (README with sources and sha256): bft-go-base c32454f vectors.json (dfcf63a0) and 81ee667 max-entry.json (c4c59703). Entries and decode verdicts/error classes match; the 95,365-byte max entry decodes, re-encodes equal, is signed by all 256 genesis members and verifies as successor.

Mutants (each caught): byte cap +1, members 257, signatures 257, node id 129, weight 2^40+1, quorum signature cap removed, lenient UTF-8, array/map header bounds removed, empty-hash allowed, 64-byte signature padded, recovery unbound, duplicate key allowed, member order >=->>, threshold unchecked. Equivalent: dropping the explicit 0x02/0x03 prefix test (BouncyCastle refuses a 33-byte uncompressed prefix anyway).

Evidence: ./gradlew test checkstyleMain animalsnifferMain under Temurin 11 green. Not merged by me; owner list.

…res, bounded CBOR; shared entry and max-entry vectors

TrustBaseEntry: exact 10-field array, deterministic re-encoding check, entry id = SHA-256(sigBytes), unsigned-64 epochs and weights, UTF-8 byte-order member sort, structure rules, exact threshold, strict 65-byte low-S recoverable signatures, successor check. Bounds: 128 KiB, 256 members, 256 signatures, 128-byte node ids; counts are checked from the array and map headers before any element is read (CborDeserializer.decodeArrayAtMost/decodeMapAtMost). decodeTextString is strict UTF-8 (was platform default, replacement). Vendored byte for byte: bft-go-base c32454f vectors (dfcf63a0) and 81ee667 max-entry (c4c59703).
@ristik

ristik commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

java#2 at 7147e87: no blockers. APPROVE once CI is green. Vectors: trust-base-v2/vectors.json (dfcf63a0…, bft-go-base c32454f) and max-entry/v1/max-entry.json (c4c59703…, 81ee667) are byte-identical to sdk-rust main's. Codec: the decode is strict. There's a byte budget before parsing, member and signature counts from the array and map headers before any element is read (decodeArrayAtMost and decodeMapAtMost), and a re-encode equality check. The signature map is encoded in canonical order (CborMap sorts by encoded key bytes, so a shorter key comes first, as in Go) and held in memory in node-ID byte order. So this codec doesn't have the mixed-length signer bug Rust had (rs#19). Nits (not blocking): (1) Add a mixed-length signer round-trip test (node1, node10, node2), as Rust and JS now have. Nothing pins this today. (2) decodeTextString is now strict UTF-8 SDK-wide, where it used to be new String(bytes) with the platform charset. That's right and matches Go, JS and Rust, but it changes behaviour for every text field, so it's worth a changelog line.

@ristik ristik closed this Nov 8, 2026
@ristik ristik reopened this Nov 8, 2026
@ristik

ristik commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

APPROVE at 7147e87, for the owner's list. CI build (which includes javadoc) is green at this head. My review is above.

@ristik
ristik changed the base branch from dev3/java-1-network-version to main November 8, 2026 03:00
@ristik
ristik merged commit b5955fe into main Nov 8, 2026
1 check passed
@ristik
ristik deleted the dev3/java-2-entry branch November 14, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant